// router.js

import { createRouter, createWebHistory } from 'vue-router';

const getRoutes = () => {
  const files = import.meta.glob('../views/**/*.vue');
  return Object.entries(files).reduce((routes, [path, component]) => {
    const name = path.match(/\.\/views\/(.*)\.vue$/)[1];
    const componentName = path.split('/').slice(-2, -1)[0];
    routes.push({
      path: `/${name.toLowerCase()}`,
      componentName,
      component: component.default || component,
    });
    return routes;
  }, []);
};
const router = createRouter({
  history: createWebHistory(),
  routes: getRoutes(),
});

export default router;
